<?php

Class story_model extends CI_Model {

    public function __construct() {
        $this->load->database();
    }

    public function getDiagnosticStory($level = '') {
        if (empty($level)) {
            $this->db->select('s.story_id,s.title,s.content,s.book_number, l.colorhex,l.level_name');
            $this->db->from('story s,level l');
            $this->db->where('s.level_number', '1');
            $this->db->where('s.type', 'D');
            $this->db->where('s.level_number = l.level_number');
        } else {
            $this->db->select('s.story_id,s.title, s.author,s.book_number, s.content,l.colorhex,l.level_name');
            $this->db->from('story s,level l');
            $this->db->where('s.level_number', $level);
            $this->db->where('s.type', 'D');
            $this->db->where('s.level_number = l.level_number');
        }
        $query = $this->db->get();
        return $query->row_array();
    }

    public function getStory($criteria, $level) {
        $this->db->select('s.*,l.colorhex,l.level_name');
        $this->db->from('story s,level l');
        $this->db->where('s.criteria_id', $criteria);
        $this->db->where('s.level_number', $level);
        $this->db->where('s.level_number = l.level_number');
        $this->db->where('s.type', 'N');
        $this->db->order_by('RAND()');
        $query = $this->db->get();
        return $query->row_array();
    }
    
    public function testing($story) {
        $this->db->select('s.story_id,s.title, s.author, s.content,s.book_number,l.colorhex,l.level_name');
        $this->db->from('story s,level l');
        $this->db->where('s.story_id', $story);
        $this->db->where('s.level_number = l.level_number');
        $query = $this->db->get();
        return $query->row_array();
    }

}

?>
